home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
edit
/
pt20pc.zip
/
PT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-02-04
|
18KB
|
639 lines
#include "pt.h"
#include "direct.h"
#include "malloc.h"
#include "string.h"
#include "conio.h"
#include "io.h"
#include "process.h"
#include "stdlib.h"
#include "time.h"
extern void criterr(void);
extern void overlay(int);
void
/* XTAG:main */
main(argc, argv)
unsigned char *argv[];
{
/**************************************************************************/
/* Declare the external variables */
/**************************************************************************/
extern struct window *windows, *windowList;
extern unsigned char msgBuffer[];
extern unsigned char startDirectory[];
extern unsigned char currentDirectory[];
extern unsigned char startDrive;
extern unsigned char currentDrive;
extern unsigned char scrMapReset;
extern unsigned int dispMemory;
extern int debug;
extern union REGS rin, rout;
extern struct window *selWindow;
extern long selBegin, selEnd;
extern int selMode;
extern int undoSize;
extern int nextChange;
extern int addHandle;
extern unsigned char addFile[];
extern long addPosition;
extern int brIntCom[];
extern int initialWindows;
extern struct changeItem scrapBuffer;
extern struct SREGS segRegs;
extern unsigned char saveVideoMode;
extern int scrRows, scrCols;
extern unsigned char filePattern[];
extern unsigned char tagPattern[];
extern unsigned char tagMarker[];
extern struct window *activeWindow;
extern int menuLine;
extern int descrFileId;
extern jmp_buf breakEnv;
#ifdef OVERLAYS
extern int overlayVector;
#endif
extern int readOnly;
extern int supressFileMsgs;
extern struct menuBlock far *menus[];
extern unsigned char *copyRightMsg;
extern unsigned char *userMessages[];
extern unsigned char far * fileHandleTable;
extern int maxFiles;
extern struct openFile *files;
extern time_t timeOfLastSave;
extern unsigned char far *menuSpace;
/**************************************************************************/
/* Declare the local variables */
/**************************************************************************/
int i, j, k, row, col, where;
int deltaRow, deltaCol, nWindows, topMode;
unsigned char *p;
unsigned int far * fp;
unsigned char far * oldTable;
struct window *w;
int lastState = 0; /* restore the last state of the editor */
int hideFiles;
/**************************************************************************/
/* Save the old video mode and set a compatible video mode to use */
/**************************************************************************/
/* determine the current display mode */
rin.h.ah = 15;
int86(0x10, &rin, &rout);
saveVideoMode = rout.h.al;
switch( saveVideoMode ) {
case 7: /* monochrome display */
dispMemory = 0xB000;
break;
case 4: /* 320x200 color */
rin.h.al = 3; /* 80x25 color */
goto setMode;
case 5: /* 320x200 b&w */
case 6: /* 640x200 b&w */
rin.h.al = 2; /* 80x25 b&w */
setMode:
rin.h.ah = 0; /* set video mode */
int86(0x10, &rin, &rout);
default:
dispMemory = 0xB800;
break;
}
/* get the segment registers */
segread(&segRegs);
/**************************************************************************/
/* Get the current directory and drive so we can restore then on exit */
/**************************************************************************/
(void)getcwd(&startDirectory[0], FILENAMESIZE);
strcpy(currentDirectory, startDirectory);
startDrive = getDefaultDrive();
currentDrive = startDrive;
/**************************************************************************/
/* Read in the initialization file but first */
/* set the variables it might change from their default values */
/**************************************************************************/
/* set up the menu blocks */
/* This one is for dynamic menus (OPTIONS and TOPLIST and HELP) */
menus[0] = (struct menuBlock far *)_fmalloc(sizeof(struct menuBlock));
/* initialize the other menus to not yet allocated */
for(i = 1; i < NMENUS; ++i)
menus[i] = (struct menuBlock far *)NULL;
/* set up space for the menu characters */
menuSpace = (unsigned char far *)_fmalloc(MENUSPACE);
/* set up variables */
addFile[0] = '\0';
strcpy(filePattern, "*.*");
strcpy(tagPattern, "*.c|*.h|*.asm");
strcpy(tagMarker, "XTAG:");
/* set up the default asciiMap so that setup can alter it */
initKeymaps();
/* read the setup file */
if( setup() ) {
cprintf(
"Cannot find \"pt.ini\" in this directory or the PATH.\r\nExiting.\r\n");
exit(1);
}
/**************************************************************************/
/* Allocate a new file handle table to allow more than 20 open files */
/* then allocate the open file table and the window structures */
/**************************************************************************/
if( _osmajor == 3 ) { /* only works for DOS 3.x */
if( 0 <= _osminor && _osminor <= 20 ) {
/* version 3.00, 3.10, and 3.20 only */
/* allocate space for the file handles */
fileHandleTable = (unsigned char far *)_fmalloc(maxFiles);
/* find the current file handle table in the PSP */
FP_OFF(fp) = 0x32; /* at 0x32 in PSP */
FP_SEG(fp) = _psp;
row = *fp; /* get the size of the current table */
FP_OFF(oldTable) = *(fp+1); /* addr of current table */
FP_SEG(oldTable) = *(fp+2);
/* copy current table to new table */
for(i = 0; i < row; ++i )
fileHandleTable[i] = oldTable[i];
/* mark the rest of the handles in the new table */
/* as unopened (0xFF) */
for(i = row; i < maxFiles; ++i)
fileHandleTable[i] = 0xFF;
/* install the new table by changing the PSP fields */
*fp = (unsigned int)maxFiles;
*(fp+1) = FP_OFF(fileHandleTable);
*(fp+2) = FP_SEG(fileHandleTable);
} else if( _osminor >= 30 ) {
/* we can do the same thing wiht a simple DOS call! */
rin.h.ah = 0x67; /* set handle count */
/* Steve Gibson's TSR example added the +1 so I am too */
/* just to be sure that I get enough handles */
rin.x.bx = maxFiles + 1;
intdos(&rin, &rout);
} else
maxFiles = 20;
} else
maxFiles = 20;
/* allocate an extra file structure for use in copymove.c (insScrap) */
files = (struct openFile *)malloc((maxFiles+1) * sizeof(struct openFile));
windows = (struct window *)malloc(maxFiles * sizeof(struct window));
if( files == NULL || windows == NULL) {
cprintf("Too many files (out of memory). Reduce maxFiles\r\n");
exit(1);
}
/**************************************************************************/
/* call various initialization routines */
/**************************************************************************/
initWindows();
initFileio();
initChanges();
/**************************************************************************/
/* Process the command line options and arguments */
/**************************************************************************/
for(i = 1; i < argc; i++) {
if( argv[i][0] == '/' || argv[i][0] == '-' ) {
for(j = 1; argv[i][j] != '\0'; j++) {
switch( argv[i][j] ) {
case 'l': /* restore last state */
lastState = 1;
break;
case 'o': /* overlaid windows */
initialWindows = 0;
break;
case 'h': /* horizontal split */
initialWindows = 1;
break;
case 'v': /* vertical split */
initialWindows = 2;
break;
case 'r': /* read only mode */
readOnly = 1;
break;
case 'd': /* debug flag initial value */
debug = argv[i][++j] - '0';
break;
default:
cprintf("usage: pt [/hlov] [file1] [file2] ...\r\n");
break;
}
}
} else /* we have reached the end of the comamnd line options */
break;
}
initMouse(5, 10, 1);
/* clear the screen */
scrollUp(0, 0, 0, scrRows-1, scrCols-1, 0x7);
/**************************************************************************/
/* create the menu line